<!---admin login check--->
<cfset request.userlevel = '99999'>
<cfset request.id = '0'>
<cfif isdefined('form.admin_username') AND isdefined('form.admin_password')>
	<cfif len(trim(form.admin_password)) GT 0>
		<cfinvoke component="cfcs.admin.admin" method="login" returnvariable="isloggedin" user="#form.admin_username#" pass="#form.admin_password#" />
        <cflock scope="session" type="readonly" timeout="10">
            <cfset request.admin_username = session.admin_username>
            <cfset request.admin_password = session.admin_password>
        </cflock>			
	</cfif>

	<cfif len(trim(form.vcode)) GT 0>
	    <cfinvoke component="cfcs.common.captcha" method="compareit" textstring="#form.vcode#" encstring="#form.captcha_check#" returnvariable="cpass">
	<cfelse>
    	<cfset cpass = 0>
    </cfif>
    
    <cfif cpass IS 0>
		<!---captcha failed so kill session--->
        <cfinvoke component="cfcs.admin.admin" method="logoff" returnvariable="void">
        <cfset errormsg = request.lang.login_captchafail>
	</cfif>
</cfif>

<cfif isdefined('session.admin_username') AND isdefined('session.admin_password')>
    <cflock scope="session" type="readonly" timeout="10">
        <cfset request.admin_username = session.admin_username>
        <cfset request.admin_password = session.admin_password>
    </cflock>
	<cfinvoke component="cfcs.admin.admin" method="checklogin" admin_user="#request.admin_username#" admin_pass="#request.admin_password#" returnvariable="isloggedin" />
	<cfif isloggedin IS 1>
         <cflock scope="session" type="readonly" timeout="10">
			<cfset request.id = session.id>
			<cfset request.userlevel = session.userlevel>
		 </cflock>
         <cfif NOT request.userlevel IS 99999>
             <cfinvoke component="cfcs.admin.admin" method="getgroupinfo" groupid="#request.userlevel#" returnvariable="qgroup" />
             <cfset request.listtype = qgroup.listtype>
        <cfelse>
        	<cfset request.listtype = 99999>
		</cfif>
	<cfelse>
		<cfset c="login">
		<cfset a="login">
		<cfset errormsg = request.lang.login_failure>
	</cfif>
<cfelse>
	<cfset c="login">
	<cfset a="login">
</cfif>

<cfinclude template="checkpermissions.cfm">